module graph
	implicit none
	
contains
	subroutine drawgraph(i)
	use formula
	implicit none
	integer i,win
	real*8 x(11),y(11),a(11),b(11),n
	
	if (i .EQ. 1) then
	!Kalau soal pertama
	x(1) = 0.01
	x(2) = 0.1
	x(3) = 0.2
	x(4) = 0.3
	x(5) = 0.4
	x(6) = 0.5
	x(7) = 0.6
	x(8) = 0.7
	x(9) = 0.8
	x(10) = 0.9
	x(11) = 0.999
	
	call fungsi(x(1),1,y(1))
	call fungsi(x(2),1,y(2))
	call fungsi(x(3),1,y(3))
	call fungsi(x(4),1,y(4))
	call fungsi(x(5),1,y(5))
	call fungsi(x(6),1,y(6))
	call fungsi(x(7),1,y(7))
	call fungsi(x(8),1,y(8))
	call fungsi(x(9),1,y(9))
	call fungsi(x(10),1,y(10))
	call fungsi(x(11),1,y(11))
	
	win = winio@('%ca[Grafik]%bg[grey]&')
	win = winio@('%pl[x_array]&',800,600,11,x,y)
	win = winio@('%ff%nl%cn%tt[OK]')
	
	else if (i .EQ. 2) then
	x(1) = 0.1
	x(2) = 0.4
	x(3) = 0.7
	x(4) = 1.0
	x(5) = 1.3
	x(6) = 1.6
	x(7) = 1.9
	x(8) = 2.2
	x(9) = 2.5
	x(10) = 2.8
	x(11) = 3.1
	
	call fungsi(x(1),2,y(1))
	call fungsi(x(2),2,y(2))
	call fungsi(x(3),2,y(3))
	call fungsi(x(4),2,y(4))
	call fungsi(x(5),2,y(5))
	call fungsi(x(6),2,y(6))
	call fungsi(x(7),2,y(7))
	call fungsi(x(8),2,y(8))
	call fungsi(x(9),2,y(9))
	call fungsi(x(10),2,y(10))
	call fungsi(x(11),2,y(11))
	
	win = winio@('%ca[Grafik]%bg[grey]&')
	win = winio@('%pl[x_array]&',800,600,11,x,y)
	win = winio@('%ff%nl%cn%tt[OK]')
	
	else if (i .EQ. 3) then
	x(1) = 0.1
	x(2) = 0.4
	x(3) = 0.7
	x(4) = 1.0
	x(5) = 1.3
	x(6) = 1.6
	x(7) = 1.9
	x(8) = 2.2
	x(9) = 2.5
	x(10) = 2.8
	x(11) = 3.1
	
	call fungsi(x(1),3,y(1))
	call fungsi(x(2),3,y(2))
	call fungsi(x(3),3,y(3))
	call fungsi(x(4),3,y(4))
	call fungsi(x(5),3,y(5))
	call fungsi(x(6),3,y(6))
	call fungsi(x(7),3,y(7))
	call fungsi(x(8),3,y(8))
	call fungsi(x(9),3,y(9))
	call fungsi(x(10),3,y(10))
	call fungsi(x(11),3,y(11))
	
	win = winio@('%ca[Grafik]%bg[grey]&')
	win = winio@('%pl[x_array]&',800,600,11,x,y)
	win = winio@('%ff%nl%cn%tt[OK]')
	
	else if (i .EQ. 4) then
    x(1) = 1.5
	x(2) = 2
	x(3) = 2.5
	x(4) = 3
	x(5) = 3.5
	x(6) = 4
	x(7) = 4.5
	x(8) = 5
	x(9) = 5.5
	x(10) = 6
	x(11) = 6.5

    a(1) = 1.5
	a(2) = 2
	a(3) = 2.5
	a(4) = 3
	a(5) = 3.5
	a(6) = 4
	a(7) = 4.5
	a(8) = 5
	a(9) = 5.5
	a(10) = 6
	a(11) = 6.5
	
	call f1d1(x(1),y(1))
	call f1d1(x(2),y(2))
	call f1d1(x(3),y(3))
	call f1d1(x(4),y(4))
	call f1d1(x(5),y(5))
	call f1d1(x(6),y(6))
	call f1d1(x(7),y(7))
	call f1d1(x(8),y(8))
	call f1d1(x(9),y(9))
	call f1d1(x(10),y(10))
	call f1d1(x(11),y(11))
    
	call cariy1d2(a(1),b(1))
	call cariy1d2(a(2),b(2))
	call cariy1d2(a(3),b(3))
	call cariy1d2(a(4),b(4))
	call cariy1d2(a(5),b(5))
	call cariy1d2(a(6),b(6))
	call cariy1d2(a(7),b(7))
	call cariy1d2(a(8),b(8))
	call cariy1d2(a(9),b(9))
	call cariy1d2(a(10),b(10))
	call cariy1d2(a(11),b(11))
	
	win = winio@('%ca[Grafik]%bg[grey]&')
	win = winio@('%pl[x_array]&',400,300,11,x,y)
	win = winio@('%pl[x_array]&',400,300,11,a,b)
	win = winio@('%ff%nl%cn%tt[OK]')

	else if (i .EQ. 5) then
	x(1) = 1.5
	x(2) = 2
	x(3) = 2.5
	x(4) = 3
	x(5) = 3.5
	x(6) = 4
	x(7) = 4.5
	x(8) = 5
	x(9) = 5.5
	x(10) = 6
	x(11) = 6.5
   	
	call f2a(x(1),y(1))
	call f2a(x(2),y(2))
	call f2a(x(3),y(3))
	call f2a(x(4),y(4))
	call f2a(x(5),y(5))
	call f2a(x(6),y(6))
	call f2a(x(7),y(7))
	call f2a(x(8),y(8))
	call f2a(x(9),y(9))
	call f2a(x(10),y(10))
	call f2a(x(11),y(11))

	win = winio@('%ca[Grafik]%bg[grey]&')
	win = winio@('%pl[x_array]&',800,600,11,x,y)
	win = winio@('%ff%nl%cn%tt[OK]')
	
	else if (i .EQ. 6) then
	x(1) = 1.5
	x(2) = 2
	x(3) = 2.5
	x(4) = 3
	x(5) = 3.5
	x(6) = 4
	x(7) = 4.5
	x(8) = 5
	x(9) = 5.5
	x(10) = 6
	x(11) = 6.5
	
	call fungsi(x(1),4,y(1))
	call fungsi(x(2),4,y(2))
	call fungsi(x(3),4,y(3))
	call fungsi(x(4),4,y(4))
	call fungsi(x(5),4,y(5))
	call fungsi(x(6),4,y(6))
	call fungsi(x(7),4,y(7))
	call fungsi(x(8),4,y(8))
	call fungsi(x(9),4,y(9))
	call fungsi(x(10),4,y(10))
	call fungsi(x(11),4,y(11))
	
	win = winio@('%ca[Grafik]%bg[grey]&')
	win = winio@('%pl[x_array]&',800,600,11,x,y)
	win = winio@('%ff%nl%cn%tt[OK]')
	
	else if (i .EQ. 7) then
	x(1) = 1.5
	x(2) = 2
	x(3) = 2.5
	x(4) = 3
	x(5) = 3.5
	x(6) = 4
	x(7) = 4.5
	x(8) = 5
	x(9) = 5.5
	x(10) = 6
	x(11) = 6.5
	
	call fungsi(x(1),5,y(1))
	call fungsi(x(2),5,y(2))
	call fungsi(x(3),5,y(3))
	call fungsi(x(4),5,y(4))
	call fungsi(x(5),5,y(5))
	call fungsi(x(6),5,y(6))
	call fungsi(x(7),5,y(7))
	call fungsi(x(8),5,y(8))
	call fungsi(x(9),5,y(9))
	call fungsi(x(10),5,y(10))
	call fungsi(x(11),5,y(11))
	
	win = winio@('%ca[Grafik]%bg[grey]&')
	win = winio@('%pl[x_array]&',800,600,11,x,y)
	win = winio@('%ff%nl%cn%tt[OK]')
	
	else if (i .EQ. 8) then
	x(1) = 1.5
	x(2) = 2
	x(3) = 2.5
	x(4) = 3
	x(5) = 3.5
	x(6) = 4
	x(7) = 4.5
	x(8) = 5
	x(9) = 5.5
	x(10) = 6
	x(11) = 6.5
    
	call fungsi(x(1),6,y(1))
	call fungsi(x(2),6,y(2))
	call fungsi(x(3),6,y(3))
	call fungsi(x(4),6,y(4))
	call fungsi(x(5),6,y(5))
	call fungsi(x(6),6,y(6))
	call fungsi(x(7),6,y(7))
	call fungsi(x(8),6,y(8))
	call fungsi(x(9),6,y(9))
	call fungsi(x(10),6,y(10))
	call fungsi(x(11),6,y(11))
	
	win = winio@('%ca[Grafik]%bg[grey]&')
	win = winio@('%pl[x_array]&',800,600,11,x,y)
	win = winio@('%ff%nl%cn%tt[OK]')
	
	else if (i .EQ. 9) then
    n=0
	x(1) = 1+n
	x(2) = 2+n
	x(3) = 3+n
	x(4) = 4+n
	x(5) = 5+n
	x(6) = 6+n
	x(7) = 7+n
	x(8) = 8+n
	x(9) = 9+n
	x(10) = 10+n
	x(11) = 11+n
	
	call fungsi(x(1),7,y(1))
	call fungsi(x(2),7,y(2))
	call fungsi(x(3),7,y(3))
	call fungsi(x(4),7,y(4))
	call fungsi(x(5),7,y(5))
	call fungsi(x(6),7,y(6))
	call fungsi(x(7),7,y(7))
	call fungsi(x(8),7,y(8))
	call fungsi(x(9),7,y(9))
	call fungsi(x(10),7,y(10))
	call fungsi(x(11),7,y(11))
	
	win = winio@('%ca[Grafik]%bg[grey]&')
	win = winio@('%pl[x_array]&',800,600,11,x,y)
	win = winio@('%ff%nl%cn%tt[OK]')
	
	endif
	end subroutine drawgraph

	subroutine f1d1(x,y)
    real*8 x,y
    y= sqrt((3*x**2-1)/2)
    end subroutine f1d1

    subroutine f1d2(x,z,y)
    real*8 x,y,z
    y= x**2-2*x+z**2+2*z-8
    end subroutine f1d2

subroutine cariy1d2(x,y)
    implicit none 
    real*8 a,b,c,jawaban,eps,deltaN,temp1,temp2,y1,y2,x,y
    integer*2 count
    integer i
    temp1 = x-0.1
    temp2 = x+0.1
    count = 0
    y1 = 0
    y2 = 0
    deltaN = abs (temp1-temp2)
    c = (temp1+temp2)/2
       
    do while ((deltaN > eps) .AND. (count < 100))
    count = count + 1
    c = (temp1+temp2)/2    
    jawaban = c
    call f1d2(x,temp1,y1)
    call f1d2(x,c,y2)
    if ((y1*y2) < 0) then
        temp2 = c
        deltaN = abs (temp1-temp2)
    else 
        temp1 = c
        deltaN = abs (temp1-temp2)
    end if    
    end do
    y = c
    end subroutine cariy1d2

end graph